package dao.auth.mybatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.auth.Authorities;
import model.auth.AuthoritiesResources;
import model.auth.Resources;

import org.springframework.stereotype.Repository;

import core.base.page.Page;
import core.base.page.PageRequest;

import dao.MyBatisBaseDao;
import dao.auth.AuthoritiesResourcesDao;

@Repository("auth.AuthoritiesResourcesDao")
public class AuthoritiesResourcesDaoImpl extends MyBatisBaseDao implements AuthoritiesResourcesDao {

	public int deleteById(Long id) {
		return  getSqlSessionTemplate().insert("auth.AuthoritiesResourcesMapper.deleteById", id);
	}

	public AuthoritiesResources getById(Long id) {
		return (AuthoritiesResources)getSqlSessionTemplate().selectOne("auth.AuthoritiesResourcesMapper.getById", id);
	}

	public int insert(AuthoritiesResources model) {
		return  getSqlSessionTemplate().insert("auth.AuthoritiesResourcesMapper.insert", model);
	}

	public List<Authorities> getAuthoritiesByResId(Long resid) {
		List<Authorities> auths = getSqlSessionTemplate().selectList("auth.AuthoritiesResourcesMapper.getAuthoritiesByResId", resid);
		return auths;
	}

	public List<Resources> getResourcesByAuthId(Long authid) {
		List<Resources> res = getSqlSessionTemplate().selectList("auth.AuthoritiesResourcesMapper.getResourcesByAuthId", authid);
		return res;
	}

	public Page<Resources> queryAuthoritiesForPage(PageRequest<HashMap> pageReq) {
		return super.queryForPage(pageReq, "auth.AuthoritiesResourcesMapper.queryForPage");
	}

	public Page<Authorities> queryResourcesForPage(PageRequest<HashMap> pageReq) {
		return super.queryForPage(pageReq, "auth.AuthoritiesResourcesMapper.queryResourcesForPage");
	}

}
